﻿using Autodesk.Revit.DB;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace Revit同步插件
{
  public static class RevitQueryTool
  {

    /// <summary>
    /// 查询过滤结果
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="doc"></param>
    /// <param name="filters"></param>
    /// <returns></returns>
    public static Collection<T> Query<T>(this Document doc, params ElementFilter[] filters) where T : Element
    {
      FilteredElementCollector clt = new FilteredElementCollector(doc);
      foreach (var f in filters)
      {
        if (null != f)
        {
          clt.WherePasses(f);
        }
      }
      var list = new List<T>();
      foreach(var item in clt.ToElements())
      {
        if(item is T t)
        {
          list.Add(t);
        }
      }
      return new Collection<T>(list);
    }


  }

}
